<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../vue.js"></script>
    <script>
        window.onload=function(){
            Vue.component('child',{
                data(){
                    return {

                    }
                },
                props:{
                    str:String,
                    str1:[Number,String],
                    str2:{
                        type:String,
                        required:true,//必填项
                    },
                    str3:{
                        type:Number,
                        default:999,//如果父组件不传值，默认值为999
                    },
                    str4:Object,
                    str5:{
                        type:Object,
                        default:function(){
                            return {
                                name:'tom'
                            }
                        }
                    },
                    str6:{
                        //自定义验证函数
                        validator(value){
                            console.log(value);//hello
                            return value.indexOf('o') !=-1
                        }
                    }
                },
                template:`
                    <div>
                        <h1>子组件：{{str}}--{{str1}}--{{str2}}---{{str3}}--{{str4}}--{{str5}}--{{str6}}</h1>
                    </div>
                `
            })
            var app=new Vue({
                el:'#app',
                data:{},
                methods:{},
                components:{
                    'parent':{
                        data(){
                            return {
                                str:'10',
                                str1:10,
                                str2:'1000',
                                str3:0,
                                str4:{
                                    name:'lisi',
                                    age:18
                                },
                                str6:'hello'
                            }
                        },
                        methods:{},
                        template:`
                            <div>
                                <h1>父组件</h1>
                                <child v-bind:str='str' v-bind:str1='str1' v-bind:str2='str2' :str3='str3' :str4='str4' :str6='str6'></child>
                            </div>
                        `
                    }
                }
            })
        }
    </script>
</head>
<body>
    <div id="app">
        <parent></parent>
    </div>
</body>
</html>